import java.applet.*;
import java.io.*;
import java.awt.*; 

public class readFileApplet extends Applet{

	

	private static Object singleton;
	int i=0;
	int ii=0;
	public String s; String tem;
	String ss; String sss;
	String dat[]=new String[100];
	String pla[]=new String[100];
	String sum[]=new String[100];
	String paint[]=new String[100];
	String d;
	String p;
public void paint(Graphics g){
	        paint=update();
	        for(int t=0;t<i;t++){
	        	tem=paint[t];
		        g.drawString(tem,40,40+t*10);
		       
		}
	        i=0;ii=0;
}
	  
public String[] update(){
	String lineContent; 
	try {
      InputStream is = getClass().getResourceAsStream("Daily.xml");
      BufferedReader br = new BufferedReader
      (new InputStreamReader(is));
      while ((lineContent = br.readLine()) != null) {
    	    int startIndex = lineContent.indexOf("<place>");
			int endIndex = lineContent.indexOf("</place>");
			if ((startIndex != -1) && (endIndex != -1)) {
			ss = lineContent.substring(startIndex+7, endIndex);
		    pla[ii]=ss;
			ii++;
			
			}
      }
     	}
    catch (Exception e) {
      e.printStackTrace();
      }
    String lineContent2;
	try {
      InputStream is2 = getClass().getResourceAsStream("Daily.xml");
      BufferedReader br2 = new BufferedReader
      
         (new InputStreamReader(is2));
      while ((lineContent2 = br2.readLine()) != null) {
    	    int startIndex2 = lineContent2.indexOf("<daily data>");
			int endIndex2 = lineContent2.indexOf("</daily data>");

			if ((startIndex2 != -1) && (endIndex2 != -1)) {
			sss = lineContent2.substring(startIndex2+12, endIndex2);
			
			dat[i]=sss;
			i++;
			}
			}
			
			
        
     	}
    catch (Exception e) {
      e.printStackTrace();
      }
 for(int j=0;j<i;j++){
	  d=dat[j];
	  p=pla[j];
	  double dnum = Double.parseDouble(d);
	  if(dnum<-1){
		  s=p+"DGreen";
	  }
	  else if(dnum>-1&&dnum<0){
		  s=p+"green";
	  }
	  else if(dnum>0&&dnum<0.5){
		  s=p+"yellow";
	  }
	  else if(dnum>0.5&&dnum<1){
		  s=p+"red";
	  }
	  else{
		  s=p+"DRed";
	  }
	 
	 
	  sum[j]=s;
	 // System.out.println( sum[j]);
	  }
      
	  return sum;
	  
}

public void start() {
		System.out.println("start()");
		if (singleton == null) {
			System.out.println("Creating singleton");
			singleton = new Object();
		} else {
			System.out.println("Singleton already created");
		}
		
		final ClassLoader cl = getClass().getClassLoader();
		System.out.println("ClassLoader: " + cl );
		

	}
	
	public void stop() {
		System.out.println("stop()");
		
	}

	public void destroy() {
	 
	   
		System.out.println("destroy()");
		
	}
}